<template>
    <div class="receive_page">
        <div v-show='now_step==2'>
            <div class="gift_share_wrap">
                <div class="gift_share_common">
                    <div class="gift_share">
                        <div class="share_top">
                            <img :src="img_url+order_data.user_image">
                            <span v-text="order_data.real_name"></span>
                        </div>
                    </div>
                    <div class="gift_words">
                        <div class="left_wrap">
                            <p>赠言：</p>
                            <p v-text="order_data.words" style="padding-top: 0.5rem"></p>
                        </div>
                    </div>
                  <!--   <div class="gift_content" :style="{'background-image': 'url(' + order_data.resource_image+')'}">
                    </div> -->
                    <div class="gift_img">
                        <img :src="order_data.resource_image">
                    </div>
                    <div class="gift_detail">
                        <ul>
                            <li class="title" v-text="order_data.resource_name">
                            </li>
                            <li class="des">
                                <div>
                                    <span v-text="guige"></span>
                                </div>
                                <div>
                                    数量：
                                    <span class="red_span">X<i v-text="order_data.gift_number"></i></span>
                                </div>
                            </li>
                        </ul>
                    </div>
    
                </div>
            </div>
            <div class="confirm_btn" v-if="order_data.gift_number==0" @click="goToAddress(0)">点击领取</div>
            <div class="confirm_btn" v-if="order_data.gift_number!=0" @click="goToAddress(1)">点击领取</div>
        </div>
    </div>
</template>

<script>
import api from '@/api/api'
export default {
    name: 'giftReceive',
    data() {
        return {
            default_user_img: require('assets/images/default_user.jpeg'),
            default_img: require('assets/images/watchs.jpg'),
            now_step: 2,
            order_data: {},
            guige: '',
            step_list: [
                {
                    name: '1.填写信息',
                    value: 0,
                    is_active: true,
                    active_img: require('assets/images/icon_write.png'),
                    normal_img: require('assets/images/icon_write.png')
                },
                {
                    name: '2.确认信息',
                    value: 1,
                    is_active: true,
                    active_img: require('assets/images/icon_confirms.png'),
                    normal_img: require('assets/images/icon_confirm.png')
                },
                {
                    name: '3.赠送礼物',
                    value: 2,
                    is_active: true,
                    active_img: require('assets/images/icon_givings.png'),
                    normal_img: require('assets/images/icon_giving.png')
                }
            ]
        }
    },
    methods: {

        getOrderInfo: function () {
            let order_params = {
                functioncode: 'give_gifts_info',
                gift_id: this.$route.params.gift_id
            }
            var _self = this;
            api.get(order_params).then((res) => {
                if (res.data.returncode == '000000') {
                    _self.order_data = res.data.record;
                   
                    if(_self.order_data.extendfield!=''){
                        _self.guige  = JSON.parse(_self.order_data.extendfield).content;
                    }

                    _self.order_data.resource_image = _self.imgCheck(_self.order_data.resource_image);
                    if (res.data.record.pay_state == 0) {
                        _self.$toast('该订单尚未支付，请支付后再来分享~');

                        let pay_url = '';
                        if (_self.wx_pay_way == 'special_self' || _self.wx_pay_way == 'special_sub') {
                            pay_url = _self.current_host + "/mp/order/pay/" + _self.$route.params.order_id + '?from=mallsend';
                        } else {//统一支付逻辑
                            pay_url = _self.unified_pay_host + "/mp/common/wxpay/order/" + _self.$route.params.order_id + '?from=mallsend';
                        }
                        window.location.replace(pay_url);
                        return;
                    } 
                }
            });
        },
        imgCheck: function (value) {
            if (value.length > 50) {
                return value;
            } else {
                return this.img_url + value;
            }
        },
        goToAddress: function (val) {
            if (val == 0) {
                this.$router.push({
                    name: 'gift_received',
                    query: { is_ok: 'sorry' },
                    params: { gift_id: this.$route.params.gift_id }
                });
            }
            if (val == 1) {
                /* this.$router.push({
                    name: 'user_address',
                    params: { gift_id: this.$route.params.gift_id }
                }); */
                this.$router.push({
                    name: 'user_confirm',
                    params: { gift_id: this.$route.params.gift_id }
                });
            }
        }
    },
    computed: {

    },
    mounted: function () {
        this.$nextTick(function () {
            this.getOrderInfo();
        });
    },
}
</script>

<style scoped>
body {
    background: #fff;
    margin: 0;
}
</style>
